home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / PUSHPOP.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  3KB  |  99 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    p u s h p o p . c                                               */
  3. /*                                                                    */
  4. /*    Directory functions for UUPC/extended                           */
  5. /*                                                                    */
  6. /*    Copyright (c) 1989 Andrew H. Derbyshire                         */
  7. /*                                                                    */
  8. /*    Changes Copyright (c) 1990 - 1992 by Kendra Electronic          */
  9. /*    Wonderworkss.  All rights reserved except as explicitly         */
  10. /*    granted by the UUPC/extended license.                           */
  11. /*--------------------------------------------------------------------*/
  12.  
  13. /*
  14.  *    $Id: PUSHPOP.C 1.2 1992/11/22 21:06:14 ahd Exp $
  15.  *
  16.  *    $Log: PUSHPOP.C $
  17.  * Revision 1.2  1992/11/22  21:06:14  ahd
  18.  * Use strpool for memory allocation
  19.  *
  20.  */
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*                        System include files                        */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <sys/types.h>
  29.  
  30. #ifdef __GNUC__
  31. #include <unistd.h>
  32. #else
  33. #include <direct.h>
  34. #endif
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                    UUPC/extended include files                     */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include "lib.h"
  41. #include "pushpop.h"
  42.  
  43. #define MAXDEPTH 10
  44.  
  45. /*--------------------------------------------------------------------*/
  46. /*                          Global variables                          */
  47. /*--------------------------------------------------------------------*/
  48.  
  49. static char *dirstack[MAXDEPTH];
  50. static depth = 0;
  51.  
  52. currentfile();
  53.  
  54. /*--------------------------------------------------------------------*/
  55. /*            Change to a directory and push on our stack             */
  56. /*--------------------------------------------------------------------*/
  57.  
  58. void PushDir( const char *directory )
  59. {
  60.    char cwd[FILENAME_MAX];
  61.    if ( depth >= MAXDEPTH )
  62.       panic();
  63.  
  64. #ifdef __TURBOC__
  65.    dirstack[depth] = newstr( getcwd( cwd  , FILENAME_MAX ));
  66. #else
  67.  
  68. #ifdef __GNUC__
  69.    dirstack[depth] = newstr( getcwd( cwd , FILENAME_MAX ) );
  70. #else
  71.    dirstack[depth] = newstr( _getdcwd( 0, cwd , FILENAME_MAX ) );
  72. #endif
  73.  
  74. #endif
  75.  
  76.    if (dirstack[depth] == NULL )
  77.    {
  78.       printerr("PushDir");
  79.       panic();
  80.    }
  81.    CHDIR( directory );
  82.    depth++;
  83.    return;
  84. } /* PushDir */
  85.  
  86. /*--------------------------------------------------------------------*/
  87. /*               Return to a directory saved by PushDir               */
  88. /*--------------------------------------------------------------------*/
  89.  
  90. void PopDir( void )
  91. {
  92.    if ( depth == 0 )
  93.       panic();
  94.  
  95.    CHDIR( dirstack[--depth] );
  96.    return;
  97.  
  98. } /* PopDir */
  99.